package com.squid.monitor.controller;

import com.squid.base.common.bean.Return;
import com.squid.monitor.model.request.InsertRedisListKeyRequest;
import com.squid.monitor.model.request.InsertRedisStringKeyRequest;
import com.squid.monitor.service.redis.RedisService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * redis控制器
 *
 * @author jinhang1
 * @date 2024/07/23
 */
@RestController
@RequestMapping("/redis")
public class RedisController {
    @Resource
    RedisService redisService;
    @PostMapping("/getAllKey")
    public Return<Object> getAllRedisKey(){
        Object resp = redisService.getAllKey();
        return Return.<Object>success().data(resp);
    }
    @PostMapping("/setStringKey")
    public Return<Object> setKey(@RequestBody InsertRedisStringKeyRequest req){
        redisService.setExpiredStringKey(req);
        return Return.<Object>success();
    }
    @GetMapping("/getStringKey")
    public Return<Object> getKey(@RequestParam String key){
        Object resp = redisService.getStringKey(key);
        return Return.<Object>success().data(resp);
    }
    @PostMapping("/setListKey")
    public Return<Object> setListKey(@RequestBody InsertRedisListKeyRequest req){
        redisService.setExpiredListKey(req);
        return Return.<Object>success();
    }
    @GetMapping("/getListKey")
    public Return<Object> getListKey(@RequestParam String key){
        Object resp = redisService.getListKey(key);
        return Return.<Object>success().data(resp);
    }
}
